#pragma once

#include "ChangeEvent.h"

#include "ValueSpecification.h"

namespace uml {

ChangeEvent::ChangeEvent(const QString& umlType)
    : Event(umlType) {}

void ChangeEvent::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Event::fromJson(json, errorList);
    changeExpression_ = JsonSerializable::create<ValueSpecification>(json.value("changeExpression"), errorList);

}

void ChangeEvent::toJson(QJsonObject& json) {
    Event::toJson(json);
    if (changeExpression_) {
        QJsonObject changeExpression_json;
        changeExpression_->toJson(changeExpression_json);
        json.insert("changeExpression", changeExpression_json);
    }
}

/// <summary>
/// changeExpression getter
/// A Boolean-valued ValueSpecification that will result in a ChangeEvent whenever
/// its value changes from false to true.
/// </summary>
shared_ptr<ValueSpecification> ChangeEvent::changeExpression() const {
    return changeExpression_;
}

/// <summary>
/// changeExpression setter
/// A Boolean-valued ValueSpecification that will result in a ChangeEvent whenever
/// its value changes from false to true.
/// </summary>
void ChangeEvent::setChangeExpression(shared_ptr<ValueSpecification> value) {
    changeExpression_ = value;
}

} // namespace uml
